home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / MacPerl ƒ / Perl Source ƒ / MacPerl / Vars2Copy < prev   
Text File  |  1993-12-08  |  1KB  |  73 lines

  1. Perl -Sx "{0}" {"Parameters"}
  2. Exit 0
  3.  
  4. #!perl
  5.  
  6. open(CONDITION, shift @ARGV) || die "Couldn't open condition";
  7.  
  8. while (<CONDITION>) {
  9.     $cond .= $_;
  10. }
  11.  
  12. while (<>) {
  13.     last if (/^Segment "%GlobalData"/);
  14. }
  15.  
  16. $loop = <<'LOOP_HEAD' . $cond . <<'LOOP_TAIL';
  17. while (<>) {
  18.     last unless (/\S/);
  19.     
  20.     ($name, $offset, $size, $rest) = /(\S+).*-\$(.*)\(A5\).*=\$(\S+)(.*)/;
  21.     
  22.     if ($rest =~ /file=\"([^"]+)\"/) {
  23.         $file = $1;
  24.     }
  25. LOOP_HEAD
  26.     $begin = hex($offset);
  27.     $end   = $begin-hex($size);
  28.         
  29.     if (!defined $oldbegin) {
  30.         $oldbegin = $begin;
  31.     } elsif ($oldend ne $begin) {
  32.         push(@begins, $oldbegin);
  33.         push(@ends, $oldend);
  34.         $oldbegin = $begin;
  35.     }
  36.     $oldend   = $end;
  37. }
  38. LOOP_TAIL
  39.  
  40. eval $loop;
  41.  
  42. if (defined $oldbegin) {
  43.     push(@begins, $oldbegin);
  44.     push(@ends, $oldend);
  45. }
  46.  
  47. @begins = sort {$b <=> $a} @begins;
  48. @ends      = sort {$b <=> $a} @ends;
  49.  
  50. print <<END_HEADER;
  51. type 'IRng' {
  52.     wide array {
  53.         longint;
  54.         longint;
  55.     };
  56.     longint = 0;
  57.     longint = 0;
  58. };
  59.  
  60. resource 'IRng' (128) {
  61.     {
  62. END_HEADER
  63.  
  64. printf("\t\t%8d, ", shift @begins);
  65.  
  66. while (($end = shift @ends) && ($begin = shift @begins)) {
  67.     if ($end != $begin) {
  68.         printf("%8d,\n\t\t%8d, ", $end, $begin);
  69.     }
  70. }
  71.  
  72. printf("%8d\n\t}\n};\n", $end);
  73.